<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    // function Person(name) {
    //     this.name = name
    // }
    // new Person('小明')
</script>
<script>
    class Animal {
        constructor(name, age) {
            this.name = name
            this.age = age
        }
        // 自定义函数
        getName() {
            // 实例化对象
            console.log(this);
        }
        setName(value) {
            console.log(value);
            this.name = value
            // console.log(this);
        }
        // 静态方法  只能类去调用
        static getAge() {
            console.log(this);
        }
    }
    let dog = new Animal('狗', 2)
    console.log(dog);
    console.log(dog.name);
    dog.getName()
    dog.setName('猫')
    console.log(dog.name);
    console.log(dog);
    // dog.getAge() // dog.getAge is not a function
    console.dir(Animal);
    Animal.getAge()
    // 继承 extends
    class Cat extends Animal {
        constructor(name, age, color) {
            // this.name = name
            // this.age = age
            // super 指代的父类 
            super(name, age)
            // 写在super下面 因为this指向问题
            this.color = color
        }
        getName_1() {
            console.log('getName_1');
            super.getName()
        }
    }

    let cat = new Cat('加菲', 3, 'yellow')
    console.log(cat);
    // cat.getName()
    cat.getName_1()
</script>

</html>